package com.example.config;


import com.example.annotation.ShardRabbitListenerAnnotationBeanPostProcessor;
import com.example.lock.ShardRabbitLockManager;
import com.example.moniter.ShardRabbitListenerManager;
import com.example.registry.ShardRabbitListenerEndpointRegistry;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.context.annotation.ImportBeanDefinitionRegistrar;
import org.springframework.core.type.AnnotationMetadata;

public class ShardRabbitBootstrapConfiguration implements ImportBeanDefinitionRegistrar {
    public ShardRabbitBootstrapConfiguration() {
    }

    public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {
        if (!registry.containsBeanDefinition(ShardRabbitListenerConfigUtils.RABBIT_LISTENER_ANNOTATION_PROCESSOR_BEAN_NAME)) {
            registry.registerBeanDefinition(ShardRabbitListenerConfigUtils.RABBIT_LISTENER_ANNOTATION_PROCESSOR_BEAN_NAME, new RootBeanDefinition(ShardRabbitListenerAnnotationBeanPostProcessor.class));
        }

        if (!registry.containsBeanDefinition(ShardRabbitListenerConfigUtils.RABBIT_LISTENER_ENDPOINT_REGISTRY_BEAN_NAME)) {
            registry.registerBeanDefinition(ShardRabbitListenerConfigUtils.RABBIT_LISTENER_ENDPOINT_REGISTRY_BEAN_NAME, new RootBeanDefinition(ShardRabbitListenerEndpointRegistry.class));
        }

        if (!registry.containsBeanDefinition(ShardRabbitListenerConfigUtils.RABBIT_LISTENER_MANAGER_BEAN_NAME)) {
            registry.registerBeanDefinition(ShardRabbitListenerConfigUtils.RABBIT_LISTENER_MANAGER_BEAN_NAME, new RootBeanDefinition(ShardRabbitListenerManager.class));
        }

        if (!registry.containsBeanDefinition(ShardRabbitListenerConfigUtils.RABBIT_LISTENER_LOCK_MANAGER_BEAN_NAME)) {
            registry.registerBeanDefinition(ShardRabbitListenerConfigUtils.RABBIT_LISTENER_LOCK_MANAGER_BEAN_NAME, new RootBeanDefinition(ShardRabbitLockManager.class));
        }

    }
}
